Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AvailableBalances::balance_msat #2476

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

wvanlint
Copy link
Contributor

@wvanlint wvanlint commented Aug 6, 2023

This PR removes the AvailableBalances::balance_msat field.

After a discussion on Discord, it was mentioned ChannelMonitor::get_claimable_balances provides a more straightforward approach to the balance of a channel, which satisfies most use cases. The computation of AvailableBalances::balance_msat is complex and originally had a different purpose that is not applicable anymore.

Its computation takes into account holding cell HTLCs and fulfills inbound-claimed HTLCs since https://github.com/lightningdevkit/rust-lightning/pull/1268/files. However, the root cause of the underflow that was the motivation of that PR does not exist anymore. At that time, the amount in send_htlc was verified against the CommitmentStats (and this commitment transaction resolves the pending HTLC in the InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) state). Currently, we're verifying against AvailableBalances::next_outbound_htlc_limit_msat which does not resolve such pending HTLCs. I copied and reran the test in #1268 from the main branch and it is not possible to send an HTLC back anymore and cause an underflow (sending the return payment fails with Cannot send more than our next-HTLC maximum). This is likely why the test has been removed.

@codecov-commenter
Copy link

codecov-commenter commented Aug 6, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01% ⚠️

Comparison is base (a24626b) 90.40% compared to head (ef5be58) 90.40%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2476      +/-   ##
==========================================
- Coverage   90.40%   90.40%   -0.01%     
==========================================
  Files         106      106              
  Lines       56328    56321       -7     
  Branches    56328    56321       -7     
==========================================
- Hits        50926    50916      -10     
- Misses       5402     5405       +3     
Files Changed Coverage Δ
lightning/src/chain/chainmonitor.rs 95.03% <ø> (ø)
lightning/src/ln/channel.rs 89.44% <ø> (-0.02%) ⬇️
lightning/src/ln/channelmanager.rs 85.69% <ø> (-0.01%) ⬇️
lightning/src/routing/router.rs 93.60% <ø> (-0.04%) ⬇️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
Copy link
Contributor

Could you add a release note regarding serialization compatibility to the pending_changelog folder and a bit more detail to the commit message? Basically LGTM otherwise. thanks!

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks.

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@wvanlint wvanlint force-pushed the remove_balance_msat branch 3 times, most recently from 817548d to c1bb5d3 Compare August 9, 2023 23:40
Comment on lines -68 to -69
/// The amount that would go to us if we close the channel, ignoring any on-chain fees.
pub balance_msat: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove this, is there still a way to calculate our balance with msat precision since ChannelMonitor::get_claimable_balances will be rounded to sats?

Copy link
Contributor Author

@wvanlint wvanlint Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not currently. With regard to AvailableBalances::balance_msat, its computation was very specific to a use case that is not applicable anymore and its value is likely not what is expected. For introspection at msat precision, perhaps Channel::value_to_self_msat and the pending HTLCs can be exposed? For the latter, see #2442.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps Channel::value_to_self_msat

Hm, perhaps. Will take a look at #2442, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what would the use case be for getting a claimable balance in msat? on-chain doesn't have msats

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking just to get our channel balance in general, not necessarily on-chain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. It's nice to have a specific use case for a balance IMO, pretty vague term in lightning. Maybe something like that would be useful for accounting reasons, though 🤷‍♀️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it's probably not a big deal to not have it for now

@wvanlint wvanlint marked this pull request as ready for review August 10, 2023 06:56
@wvanlint
Copy link
Contributor Author

Adjusted documentation and serialization compatibility.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

pending_changelog/remove_balance_msat.txt Outdated Show resolved Hide resolved
Comment on lines -68 to -69
/// The amount that would go to us if we close the channel, ignoring any on-chain fees.
pub balance_msat: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what would the use case be for getting a claimable balance in msat? on-chain doesn't have msats

@wvanlint wvanlint force-pushed the remove_balance_msat branch 2 times, most recently from fb4b56f to 67b47bf Compare August 10, 2023 22:38
@@ -7550,7 +7542,7 @@ impl Readable for ChannelDetails {
(10, channel_value_satoshis, required),
(12, unspendable_punishment_reserve, option),
(14, user_channel_id_low, required),
(16, balance_msat, required),
(16, _balance_msat, option), // Backwards compatibility for removed balance_msat field.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

God rustc pisses me off for doing this - it just blindly picks a type (IIRC i64, so we're okay) and assumes that that's the type we want here. Its completely nonsense and results in code that does surprising things. Can you re-add the let _balance_msat: Option<u64> = _balance_msat below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for catching this! Re-added the type hint.

The ChannelMonitor::get_claimable_balances method provides a more
straightforward approach to the balance of a channel, which satisfies
most use cases. The computation of AvailableBalances::balance_msat is
complex and originally had a different purpose that is not applicable
anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants